/**
 * 
 */
package cn.edu.tyu.finance.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.jasper.tagplugins.jstl.core.If;

import com.mysql.jdbc.PreparedStatement;
import com.sun.xml.internal.ws.Closeable;

/**
 * MySQL数据库实用类
 * @author sunjianxiong
 * @version 1.0
 */
public class DbUtil {
	 public static void main(String[] args) {
		DbUtil dbUtil = new DbUtil();
		Connection conn = dbUtil.getConnection();
		System.out.println(conn);
	}
	 public static Connection getConnection() {
		 Connection conn = null;
		 String url = "jdbc:mysql://localhost:3306/financedb";
		 try {
			conn = DriverManager.getConnection(url, "root", "123456");
		} catch (SQLException e) {
			e.printStackTrace();
		}
		 return conn;
	 }
	 /**
	  *
	  * @param conn
	  * @param ps
	  * @param rs
	  */
	public static void backConn(Connection conn, PreparedStatement ps,ResultSet rs){
		if(rs!=null) {
			try {
				rs.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		if(conn!=null){
			try {
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	}
	
	}	
	
}
